﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using StateGrid.User;
using StateGrid.MDBservice;
using StateGrid.ZWQK;
using StateGrid.WWQK;
using StateGrid.ZWHY;
using StateGrid.WWHY;
using StateGrid.NYBG;
using StateGrid.XWLW;
using StateGrid.DLBK;
using StateGrid.JJBK;
using StateGrid.KJBK;
using StateGrid.ZHBK;
using StateGrid.ZGCG;
using StateGrid.KJCG;
using iTextSharp.text.xml;
using StateGrid.UI;


namespace StateGrid
{
    enum TTypeEditStatus
    {
        EZhongWenQiKan = 1,
        EWaiWenQiKan,
        EZhongWenHuiYi,
        EWaiWenHuiYi
    }

    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
     
    public partial class EditWindow : Window
    {
        /// <summary>
        /// 各个文库的面板
        /// </summary>
        Dictionary<string, System.Windows.Controls.UserControl> wizardPanels = new Dictionary<string,System.Windows.Controls.UserControl>();
        /// <summary>
        /// 当前用户对象
        /// </summary>
        private User.User user
        {
            get;
            set;
        }

        private System.Windows.Controls.UserControl blankWizard;

        public EditWindow(User.User aUser)
        {
            InitializeComponent();
            
            user = aUser;
            InitWizardPanels(aUser);
            

            foreach (FunctionModular fm in user.grantedModulars)
            {
                System.Windows.Controls.Button btn = new System.Windows.Controls.Button();
                btn.Content = fm.name;
                btn.Name = fm.id;
                btn.Click += this.buttonRepositorySelection_Click;
                btn.Height = 23;
                btn.Width = 135;
                btn.Margin = new Thickness(0, 10, 0, 0);
                wrapPanelRepositryButtons.Children.Add(btn);
            }

            wizardPanel.Children.Add(blankWizard);
            
            lblUsername.Content = user.name;
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            lblVersion.Content = assembly.GetName().Version.ToString();
            lblDataTime.Content = DateTime.Today.ToString("yyyy-MM-dd") + "  " + DateTime.Today.DayOfWeek.ToString();
        }

        private void InitWizardPanels(User.User aUser)
        {
            wizardPanels["zhongwenqikan"] = new TraditionWizard(new ZWQK_MDB(), aUser);
            //wizardPanels["zhongwenqikan"] = new BlankWizard();
            wizardPanels["waiwenqikan"] = new TraditionWizard(new WWQK_MDB(), aUser);
            wizardPanels["zhongwenhuiyi"] = new TraditionWizard(new ZWHY_MDB(), aUser);
            wizardPanels["waiwenhuiyi"] = new TraditionWizard(new WWHY_MDB(), aUser);
            wizardPanels["nengyuanbaogao"] = new TraditionWizard(new NYBG_MDB(), aUser);
            wizardPanels["xueweilunwen"] = new TraditionWizard(new XWLW_MDB(), aUser);
            wizardPanels["dianlibaokan"] = new TraditionWizard(new DLBK_MDB(), aUser);
            wizardPanels["jingjibaokan"] = new TraditionWizard(new JJBK_MDB(), aUser);
            wizardPanels["kejibaokan"] = new TraditionWizard(new KJBK_MDB(), aUser);
            wizardPanels["zonghebaokan"] = new TraditionWizard(new ZHBK_MDB(), aUser);
            wizardPanels["zhongguochengguo"] = new TraditionWizard(new ZGCG_MDB(), aUser);
            wizardPanels["kejichengguo"] = new TraditionWizard(new KJCG_MDB(), aUser);
            wizardPanels["guojiabiaozhun"] = new AdvanceWizard();
            
            blankWizard = new BlankWizard();
        }

        private void buttonRepositorySelection_Click(object sender, RoutedEventArgs e)
        {
            
            System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button;
            wizardPanel.Children.Clear();
            if (wizardPanels.ContainsKey(btn.Name))
            {
                wizardPanel.Children.Add(wizardPanels[btn.Name]);
                // wizardPanel.UpdateLayout();
            }
            else
            {
                wizardPanel.Children.Add(blankWizard);
            }
            //if (!iCurrentReposId.Equals(btn.Name))
            //{
            //    if (iRepos != null)
            //        iRepos.clear();
            //    iCurrentReposId = btn.Name;
            //    else if (iCurrentReposId.Equals("kejichengguo"))
            //    {
            //        iRepos = new KJCG_MDB();
            //    }
            //    else
            //        iRepos = new ZWQK_MDB();

        }

        

        

        

    }
}
